package cc.wanforme.chipmunity.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.wanforme.chipmunity.common.bean.WebResponse;
import cc.wanforme.chipmunity.controller.base.BaseController;
import cc.wanforme.chipmunity.system.po.InnerReply;
import cc.wanforme.chipmunity.system.service.interfaces.InnerReplyService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @author wanne
 * 2019年8月17日
 * 
 */
@Controller
@RequestMapping("/ireply")
public class InnerReplyController extends BaseController{

	private static final Logger log = LoggerFactory.getLogger(InnerReplyController.class);
	
	@Autowired
	private InnerReplyService innerReplyService;
	
	@RequestMapping("/add")
	@ResponseBody
	@ApiOperation("添加新的层回复")
	@ApiImplicitParam(name="InnerReply", dataType="innerReply", value="新增层回复", required=true)
	@PreAuthorize("hasAuthority('ireply:add')")
	public WebResponse addInnerReply(@RequestBody(required=true) InnerReply innerReply) {
		try {
			return innerReplyService.saveInnerReply(innerReply);
		} catch (Exception e) {
			log.error("添加层回复", e);
			return WebResponse.fail("回复失败！服务器异常！");
		}
	}
	
	
	@RequestMapping("/udpate")
	@ResponseBody
	@ApiOperation("更新层回复")
	@ApiImplicitParam(name="InnerReply", dataType="innerReply", value="根据id更新层回复，不更新replyId和userId", required=true)
	@PreAuthorize("hasAuthority('ireply:update')")
	public WebResponse updateInnerReply(@RequestBody(required=true) InnerReply innerReply) {
		try {
			return innerReplyService.updateInnerReply(innerReply);
		} catch (Exception e) {
			log.error("更新层回复", e);
			return WebResponse.fail("更新失败！服务器异常！");
		}
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	@ApiOperation("删除层回复")
	@ApiImplicitParam(name="id", dataType="Long", value="删除层回复", required=true)
	@PreAuthorize("hasAuthority('ireply:delete')")
	public WebResponse deleteInnerReply(@RequestParam(required=true) Long id) {
		try {
			return innerReplyService.removeInnerReply(id);
		} catch (Exception e) {
			log.error("删除层回复", e);
			return WebResponse.fail("删除失败！服务器异常！");
		}
	}
	
}
